package com.heima.service.impl;

import com.github.pagehelper.PageHelper;
import com.heima.mapper.NodeMapper;
import com.heima.pojo.Business;
import com.heima.pojo.Node;
import com.heima.pojo.Region;
import com.heima.pojo.dto.PagingQueryDTO;
import com.heima.pojo.vo.PagingVO;
import com.heima.service.NodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NodeServicelmpl implements NodeService {
    @Autowired
    private NodeMapper nodeMapper;
    /**
     * 查看地区详情
     *
     * @param receiveDto
     * @return
     */
    @Override
    public PagingVO<Node> getRegion(PagingQueryDTO receiveDto) {



        //查询关联区域的点位
        List<Node> node1 = nodeMapper.getRegion(receiveDto.getRegionId());
        for (Node node : node1) {
            //根据查询id地区获取地区信息
            Region regionVO = nodeMapper.getRegionInfo(receiveDto.getRegionId());
            //查询商圈信息
            Business business = nodeMapper.getBusiness(node.getBusinessId());
            node.setRegion(regionVO);
            node.setBusinessType(business);
        }
        PagingVO<Node> pagingVo = new PagingVO<>();
        pagingVo.setCurrentPageRecords(node1);
        pagingVo.setPageIndex(receiveDto.getPageIndex());
        pagingVo.setPageSize(receiveDto.getPageSize());
        int totalCount = node1.size();
        pagingVo.setTotalCount( totalCount);
        String TotalCount = String.valueOf((int) Math.ceil((double) totalCount / receiveDto.getPageSize()));
        pagingVo.setTotalPage(Integer.valueOf(TotalCount));
        return pagingVo;

    }
}
